package com.soulsdk.demo;

import com.soul.sdk.SGProxy;
import com.soul.sdk.common.CpServerConfigRequestCallback;
import com.soul.sdk.utils.SGDebug;
import com.soul.sdk.utils.json.KJSONObject;

/**
 * @author lch
 * @version Create time：2017-5-20
 * @类说明：
 */
public class VoCpServerConfig {

	private VoCpServerConfig self;

	// 字段都是沿用之前 的，虽然有些难理解，只能看注释了。。。。。
	/*
	 * @nButton String 按钮显示(1:确定,2:领取,3:购买)
	 * 
	 * @nWord boolean 价格小字是否显示(true:显示，false:不显示)
	 * 
	 * @nPlayPop boolean 是否弹窗(true:弹窗，false:不弹窗)
	 * 
	 * @nStartPop boolean 开始游戏弹窗(true:弹窗，false:不弹窗)
	 * 
	 * @nSuccessPop boolean 关卡成功弹礼包(true:弹窗，false:不弹窗)
	 * 
	 * @nFailPop boolean 关卡失败礼包(true:弹窗，false:不弹窗)
	 * 
	 * @nGoldPop boolean 金币不足弹钻石窗口(true:弹钻石窗口,false:弹计费)
	 * 
	 * @nGamePop boolean 结束角色礼包(true:弹窗，false:不弹窗)
	 * 
	 * @nEnergyPop boolean 开始礼包(true:弹窗，false:不弹窗)
	 * 
	 * @nPoword boolean 角色小字显示(true:显示，false:不显示)
	 * 
	 * @nDiaPop boolean 钻石不足弹窗(true:弹窗，false:不弹窗)
	 * 
	 * @nRoleGiftPop boolean 角色礼包(true:弹窗，false:不弹窗)
	 */

	// 按钮显示(1:确定,2:领取,3:购买)
	private int nButton = 3;
	// 价格小字是否显示(true:显示，false:不显示)
	private boolean nWord = false;
	// 是否弹窗(true:弹窗，false:不弹窗)
	private boolean nPlayPop = false;
	// 开始游戏弹窗(true:弹窗，false:不弹窗)
	private boolean nStartPop = false;
	// 关卡成功弹礼包(true:弹窗，false:不弹窗)
	private boolean nSuccessPop = false;
	// 关卡失败礼包(true:弹窗，false:不弹窗)
	private boolean nFailPop = false;
	// 金币不足弹钻石窗口(true:弹钻石窗口,false:弹计费)
	private boolean nGoldPop = false;
	// 结束角色礼包(true:弹窗，false:不弹窗)
	private boolean nGamePop = false;
	// 开始礼包(true:弹窗，false:不弹窗)
	private boolean nEnergyPop = false;
	// 角色小字显示(true:显示，false:不显示)
	private boolean nPword = false;
	// 钻石不足弹窗(true:弹窗，false:不弹窗)
	private boolean nDiaPop = false;
	// 角色礼包(true:弹窗，false:不弹窗)
	private boolean nRoleGiftPop = false;

	// 0:不开广告，1: 看完3次广告后，第二天才能看，2:看完3次广告后，冷却 5 分钟 才能看
	private int ads = 0;

	public VoCpServerConfig() {
		this.self = this;
		// 设置监听，因为 从服务端拉取数据异步操作，有可能延时；当从服务端拉取到数据时，会回调
		SGProxy.getInstance().setCpServerConfigRequestCallback(mCpServerConfigRequestCallback);
		// 获取从服务端拉取的供CP在线控制使用的数据，若此时服务端还没有返回数据则为 null，后续如果获取到将通过
		// CpServerConfigRequestCallback返回。
		KJSONObject pDataJson = SGProxy.getInstance().getCpServerConfigJSON();
		SGDebug.v(self, "VoCpServerConfig()构造函数 pDataJson >>> " + pDataJson);
		this.setData(pDataJson);
	}

	private void setData(KJSONObject pDataJson) {
		if (pDataJson != null) {

			try {
				this.nButton = pDataJson.optInt("nButton", nButton);
				this.nWord = pDataJson.optBoolean("nWord", nWord);
				this.nPlayPop = pDataJson.optBoolean("nPlayPop", nPlayPop);
				this.nStartPop = pDataJson.optBoolean("nStartPop", nStartPop);
				this.nSuccessPop = pDataJson.optBoolean("nSuccessPop", nSuccessPop);
				this.nFailPop = pDataJson.optBoolean("nFailPop", nFailPop);
				this.nGoldPop = pDataJson.optBoolean("nGoldPop", nGoldPop);
				this.nGamePop = pDataJson.optBoolean("nGamePop", nGamePop);
				this.nEnergyPop = pDataJson.optBoolean("nEnergyPop", nEnergyPop);
				this.nPword = pDataJson.optBoolean("nPword", nPword);
				this.nDiaPop = pDataJson.optBoolean("nDiaPop", nDiaPop);
				this.nRoleGiftPop = pDataJson.optBoolean("nRoleGiftPop", nRoleGiftPop);
				this.ads = pDataJson.optInt("ads", ads);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	}

	/**
	 * 客户端获取到服务端在线配置信息时的回调
	 */
	private CpServerConfigRequestCallback mCpServerConfigRequestCallback = new CpServerConfigRequestCallback() {

		@Override
		public void onCallback(KJSONObject pDataJSON) {
			SGDebug.i(self, "CpServerConfigRequestCallback >>> " + pDataJSON);
			if (pDataJSON != null) {
				self.setData(pDataJSON);
			}
		}
	};

	public int getnButton() {
		return nButton;
	}

	public boolean isnWord() {
		return nWord;
	}

	public boolean isnPlayPop() {
		return nPlayPop;
	}

	public boolean isnStartPop() {
		return nStartPop;
	}

	public boolean isnSuccessPop() {
		return nSuccessPop;
	}

	public boolean isnFailPop() {
		return nFailPop;
	}

	public boolean isnGoldPop() {
		return nGoldPop;
	}

	public boolean isnGamePop() {
		return nGamePop;
	}

	public boolean isnEnergyPop() {
		return nEnergyPop;
	}

	public boolean isnPword() {
		return nPword;
	}

	public boolean isnDiaPop() {
		return nDiaPop;
	}

	public boolean isnRoleGiftPop() {
		return nRoleGiftPop;
	}

	public int getAds() {
		return ads;
	}

}
